<?php
/*
 * @Description: 账户服务
 * @Author: franktrue 807615827@qq.com
 * @Date: 2021-07-13 12:45:54
 * @LastEditTime: 2021-07-13 16:40:59
 */
namespace App\Rpc\Service;

use App\Model\Entity\AccountUser;
use App\Rpc\Lib\AccountUserInterface;
use Swoft\Rpc\Server\Annotation\Mapping\Service;

/**
 * Class AccountUserService
 *
 * @since 2.0
 *
 * @Service()
 */
class AccountUserService implements AccountUserInterface
{
    /**
     * @param int $id
     * @param array $columns
     * 
     * @return array
     */
    public function get(int $id, array $columns = ['*']): array
    {
        return AccountUser::find($id, $columns);
    }

    /**
     * @param array $attributes
     * 
     * @return int
     */
    public function create(array $attributes): int
    {
        $user = AccountUser::new($attributes);
        $user->save();
        return $user->getId();
    }

    /**
     * @param int $id
     * @param array $attributes
     * 
     * @return bool
     */
    public function update(int $id, array $attributes): bool
    {
        return AccountUser::find($id)->update($attributes);
    }

    /**
     * @param int $id
     * 
     * @return bool
     */
    public function delete($id): bool
    {
        return AccountUser::find($id)->update(['status' => 1]);
    }
}